package com.jtjrenren.android.taxi.passenger.core.order.account;

import android.app.Activity;
import android.content.Intent;
import android.widget.EditText;
import android.widget.TextView;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseActivity;
import com.jtjrenren.android.taxi.passenger.manger.AppManger;
import com.library.utils.RegexUtils;
import com.library.utils.StringUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/2/15.
 */
public class OrderAccountChooseActivity extends BaseActivity {
    public static String RETURN_VALUE = "value";

    @BindView(R.id.choose_account_phone)
    EditText et_phone;
    @BindView(R.id.choose_account_myphone)
    TextView tv_myPhone;

    public static Intent getDiyIntent(Activity context, String phone) {
        Intent intent = new Intent(context, OrderAccountChooseActivity.class);
        intent.putExtra("phone", phone);
        return intent;
    }

    @Override
    public int getLayoutId() {
        return R.layout.atydlg_choose_account;
    }

    @Override
    public void init() {
        if (getIntent().hasExtra("phone")) {
            String phone = getIntent().getStringExtra("phone");
            if (!StringUtils.isEmpty(phone))
                et_phone.setText(phone);
        }

        tv_myPhone.setText(AppManger.getInstance().user.getPhone());
    }


    @OnClick(R.id.choose_account_ok)
    public void commit() {
        String phone = et_phone.getText().toString().trim();
        if (!StringUtils.isEmpty(phone) && RegexUtils.isPhoneNo(phone)) {
            setResultBak(phone);
        } else {
            displayShort(getString(R.string.phonedesc));
        }
    }

    @OnClick(R.id.choose_account_cancle)
    public void cancle() {
        finish();
    }

    @OnClick(R.id.choose_account_myphone)
    public void useMinePhone() {
        setResultBak("");
    }

    private void setResultBak(String phone) {
        Intent data = new Intent();
        data.putExtra(RETURN_VALUE, phone);
        setResult(RESULT_OK, data);
        finish();
    }
}
